home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / stdg44.exe / lha / BULLMENU.C < prev    next >
C/C++ Source or Header  |  1994-01-10  |  7KB  |  199 lines

  1. #include "stdg.h"
  2. #include "bullseye.h"
  3.  
  4. /*  Forward declarations of menu functions  */
  5.  
  6. void    close_front(void);
  7.  
  8. void    set_win_width(void);
  9. void    set_win_fore(void);
  10. void    set_win_back(void);
  11.  
  12. /*  Menu state variables  */
  13.  
  14. #define NWIDTHS 11
  15. #define NCOLOURS 12
  16.  
  17. short   always_enabled      = Enabled;
  18. short   can_modify_win      = Disabled;
  19. short   can_make_new_win    = Enabled;
  20. short   can_close_win       = Disabled;
  21.  
  22. short   can_width[NWIDTHS];
  23. short   can_fore[NCOLOURS];
  24. short   can_back[NCOLOURS];
  25.  
  26. /*  Menu definitions  */
  27.  
  28. /*  A single pull-down menu is just an array of menuitems.
  29.  *  The first menuitem specifies the name of the whole menu.
  30.  *  Each menuitem consists of four things:
  31.  *  1. A string which is the name of the menu item.
  32.  *  2. A shortcut key equivalent.
  33.  *  3. The address of a state variable indicating the state of the item.
  34.  *     Valid states are Disabled, Enabled, Disabled+Ticked, Enabled+Ticked.
  35.  *  4. The address of a function to call when the item is selected.
  36.  */
  37.  
  38. menuitem file_menu[] = {
  39.     { "&File",          0,      &always_enabled,    NULL },
  40.     { "New &Oval",      'O',    &can_make_new_win,  &new_oval },
  41.     { "New &Rectangle", 'R',    &can_make_new_win,  &new_rectangle },
  42.     { "New &Triangle",  'T',    &can_make_new_win,  &new_triangle },
  43.     { "&Close",         'W',    &can_close_win,     &close_front },
  44.     { "-",              0,      NULL,               NULL },
  45.     { "&Quit",          'Q',    &always_enabled,    &gexit },
  46.     { NULL,             0,      NULL,               NULL }
  47. };
  48.  
  49. menuitem edit_menu[] = {
  50.     { "&Edit",          0,      &always_enabled,    NULL },
  51.     { "&Undo",          'Z',    NULL,               NULL},
  52.     { "-",              0,      NULL,               NULL},
  53.     { "Cu&t",           'X',    NULL,               NULL},
  54.     { "&Copy",          'C',    NULL,               NULL},
  55.     { "&Paste",         'V',    NULL,               NULL},
  56.     { "Clea&r",         0,      NULL,               NULL},
  57.     { "Select &All",    'A',    NULL,               NULL},
  58.     { NULL,             0,      NULL,               NULL }
  59. };
  60.  
  61. menuitem width_menu[] = {
  62.     { "&Width",         0,      &can_modify_win,    NULL },
  63.     { "&1",             '1',    &can_width[1],      &set_win_width },
  64.     { "&2",             '2',    &can_width[2],      &set_win_width },
  65.     { "&3",             '3',    &can_width[3],      &set_win_width },
  66.     { "&4",             '4',    &can_width[4],      &set_win_width },
  67.     { "&5",             '5',    &can_width[5],      &set_win_width },
  68.     { "&6",             '6',    &can_width[6],      &set_win_width },
  69.     { "&7",             '7',    &can_width[7],      &set_win_width },
  70.     { "&8",             '8',    &can_width[8],      &set_win_width },
  71.     { "&9",             '9',    &can_width[9],      &set_win_width },
  72.     { "1&0",            '0',    &can_width[10],     &set_win_width },
  73.     { NULL,             0,      NULL,               NULL }
  74. };
  75.  
  76. menuitem fore_menu[] = {
  77.     { "Fo®round",    0,      &can_modify_win,    NULL },
  78.     { "Blac&k",         0,      &can_fore[1],       &set_win_fore },
  79.     { "&White",         0,      &can_fore[2],       &set_win_fore },
  80.     { "&Dark Grey",     0,      &can_fore[3],       &set_win_fore },
  81.     { "Gr&ey",          0,      &can_fore[4],       &set_win_fore },
  82.     { "&Light Grey",    0,      &can_fore[5],       &set_win_fore },
  83.     { "&Red",           0,      &can_fore[6],       &set_win_fore },
  84.     { "&Green",         0,      &can_fore[7],       &set_win_fore },
  85.     { "&Blue",          0,      &can_fore[8],       &set_win_fore },
  86.     { "&Cyan",          0,      &can_fore[9],       &set_win_fore },
  87.     { "&Magenta",       0,      &can_fore[10],      &set_win_fore },
  88.     { "&Yellow",        0,      &can_fore[11],      &set_win_fore },
  89.     { NULL,             0,      NULL,               NULL }
  90. };
  91.  
  92. menuitem back_menu[] = {
  93.     { "Ba&ckground",    0,      &can_modify_win,    NULL },
  94.     { "Blac&k",         0,      &can_back[1],       &set_win_back },
  95.     { "&White",         0,      &can_back[2],       &set_win_back },
  96.     { "&Dark Grey",     0,      &can_back[3],       &set_win_back },
  97.     { "Gr&ey",          0,      &can_back[4],       &set_win_back },
  98.     { "&Light Grey",    0,      &can_back[5],       &set_win_back },
  99.     { "&Red",           0,      &can_back[6],       &set_win_back },
  100.     { "&Green",         0,      &can_back[7],       &set_win_back },
  101.     { "&Blue",          0,      &can_back[8],       &set_win_back },
  102.     { "&Cyan",          0,      &can_back[9],       &set_win_back },
  103.     { "&Magenta",       0,      &can_back[10],      &set_win_back },
  104.     { "&Yellow",        0,      &can_back[11],      &set_win_back },
  105.     { NULL,             0,      NULL,               NULL }
  106. };
  107.  
  108.  
  109. menu menubar[] = {
  110.     file_menu, edit_menu, width_menu, fore_menu, back_menu, NULL
  111. };
  112.  
  113.  
  114. /* colours in menu order */
  115.  
  116. pixval colour_table[] = {
  117.     0,
  118.     BLACK,      WHITE,
  119.     DKGREY,     GREY,       LTGREY,
  120.     RED,        GREEN,      BLUE,
  121.     CYAN,       MAGENTA,    YELLOW
  122. };
  123.  
  124. void menuinit(void) /* set menu states so the correct items are enabled */
  125. {
  126.     int i;
  127.  
  128.     for (i=0; i<NWIDTHS; i++)
  129.         can_width[i] = Enabled;
  130.     for (i=0; i<NCOLOURS; i++)
  131.         can_fore[i] = can_back[i] = Enabled;
  132. }
  133.  
  134. short find_colour(pixval v) /* find a colour's menu item number */
  135. {
  136.     short i;
  137.  
  138.     for (i=1; i<NCOLOURS; i++)
  139.         if (colour_table[i] == v)
  140.             return i;
  141.  
  142.     return 0;
  143. }
  144.  
  145. void adjust_menus(void) /* this is called before a menu is displayed */
  146. {
  147.     window *wp = active_window;
  148.     int i;
  149.  
  150.     for (i = 1; i < NWIDTHS; i++)       /* uncheck all the widths */
  151.         can_width[i] = Enabled;
  152.  
  153.     for (i = 1; i < NCOLOURS; i++) {    /* uncheck all the colours */
  154.         can_fore[i] = Enabled;
  155.         can_back[i] = Enabled;
  156.     }
  157.  
  158.     if ((wp == NULL) || (wp->flags & Workspace))
  159.     {
  160.         /* there is no frontmost window or it is the workspace window */
  161.  
  162.         can_modify_win = can_close_win = Disabled;
  163.     }
  164.     else if (wp->data != NULL)
  165.     {
  166.         /* the frontmost window is a bullseye window */
  167.  
  168.         can_modify_win = can_close_win = Enabled;
  169.  
  170.         /* check the width and the colours for the frontmost window */
  171.  
  172.         can_width[get_width(wp)]            = Enabled + Ticked;
  173.         can_fore[find_colour(get_fore(wp))] = Enabled + Ticked;
  174.         can_back[find_colour(get_back(wp))] = Enabled + Ticked;
  175.     }
  176. }
  177.  
  178. /*  Menu functions called automatically when the user chooses them  */
  179.  
  180. void close_front(void)
  181. {
  182.     close(active_window);
  183. }
  184.  
  185. void set_win_width(void)
  186. {
  187.     set_width(active_window, menu_item); /* menu_item is set by the library */
  188. }
  189.  
  190. void set_win_fore(void)
  191. {
  192.     set_fore(active_window, colour_table[menu_item]);
  193. }
  194.  
  195. void set_win_back(void)
  196. {
  197.     set_back(active_window, colour_table[menu_item]);
  198. }
  199.